package com.anolesoft.amljmes.foreknow.controller;

import com.anolesoft.amljmes.foreknow.bo.MesBzzPtdmx;
import com.anolesoft.amljmes.foreknow.dto.MesBzzPtdDto;
import com.anolesoft.amljmes.foreknow.service.MesBzzPtdmxService;
import com.anolesoft.common.core.constant.HttpStatus;
import com.anolesoft.common.core.domain.LoginUser;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.yr.demo.PageResult;
import com.anolesoft.yr.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mesbzzptdmx")
public class MesBzzPtdmxController {

    @Autowired
    private MesBzzPtdmxService service;

    @RequestMapping(value = "/query" , method = RequestMethod.POST)
    public AjaxResult queryMesBzzPtjhInfo(@RequestBody MesBzzPtdDto dto){
        Integer pageNum = dto.getPageNum();
        Integer pageSize = dto.getPageSize();
        HashMap map = new HashMap();
        map.put("list",dto.getIds());
        Map map1 = service.count(map);
        LoginUser loginUser = com.anolesoft.yr.util.SecurityUtils.getLoginUser();
        String fcode = loginUser.getFacCode();
        map1.put("fcode",fcode);
        List<String> you = (List<String>) map1.get("you");
        List<String> wu = (List<String>) map1.get("wu");
        // 数据汇总
        List<MesBzzPtdmx> allList = new ArrayList<>();
        if (you.size() != 0){
            // 保留过查询
            List<MesBzzPtdmx> list1 = service.querylist(map1);
            for (MesBzzPtdmx mxyou:
            list1) {
                allList.add(mxyou);
            }
        }
        if (wu.size() != 0){
            // 未保留查询
            List<MesBzzPtdmx> list2 = service.querylist1(map1);
            for (MesBzzPtdmx mxwu:
                    list2) {
                allList.add(mxwu);
            }
        }
        //处理虚拟保留数量(预留位置)
//        int endIndex = pageNum * pageSize > allList.size() ? allList.size() : pageNum * pageSize;
//        List<MesBzzPtdmx> list = allList.subList( (pageNum-1) *pageSize, endIndex);
        PageResult pageResult = new PageResult(allList, pageSize, pageNum, allList.size());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,pageResult);
    }
}
